﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using LispInterpretor;
using LispInterpretor.DataTypes;

namespace UnitTests
{
    [TestClass]
    public class TestRest
    {
        [TestMethod]
        [ExpectedException(typeof(InvalidProgramException))]
        public void TestRestWithGarbage()
        {
            Evaluator.Eval("(rest 2)");
        }

        [TestMethod]
        public void TestRestWithSensibleList()
        {
            object result = Evaluator.Eval("(rest (1 2 3))");

            Assert.IsTrue(result is IList<object>);

            IList<object> list = (IList<object>) result;

            Assert.AreEqual(2, list.Count);
            Assert.AreEqual(new Number(2), list[0]);
            Assert.AreEqual(new Number(3), list[1]);
        }

        [TestMethod]
        public void TestRestWithSingleItemedList()
        {
            object result = Evaluator.Eval("(rest (1))");

            Assert.IsTrue(result is IList<object>);

            IList<object> list = (IList<object>)result;

            Assert.AreEqual(0, list.Count);
        }

        [TestMethod]
        [ExpectedException(typeof(InvalidProgramException))]
        public void TestRestWithNoItems()
        {
            object result = Evaluator.Eval("(rest ())");

            Assert.IsTrue(result is IList<object>);

            IList<object> list = (IList<object>)result;

            Assert.AreEqual(0, list.Count);
        }
    }
}
